<template>
	<view class="fans">
		<scroll-view class="scroll-view_H" scroll-x="true" v-if="!embedded">
			<view class="slide_type_list">
				<view class="slide_type_list_view" v-for="(item,index) in typeList" :key="index"
					:class="{is_selected:active==index}" @click="changeType(item,index)">
					<view>{{item.name}}</view>
				</view>
			</view>
		</scroll-view>
		<view class="invitecode" v-if="active == 0 && !embedded">
			<view class="mycode">
				<view class="title">
					<view class="circle1"></view>
					<view class="circle2"></view>
					<text class="name">我的邀请码</text>
					<view class="circle2"></view>
					<view class="circle1"></view>
				</view>
				<button type="default" class="code_btn">{{userinfo.invitation_code}}</button>
		
				<view class="line_raduis">
					<view class="half_right_raduis">
		
					</view>
					<view class="line_gray">
		
					</view>
					<view class="half_left_raduis">
		
					</view>
				</view>
				<view class="invite_img">
					<image :src="codeUrl"></image>
				</view>
				<view class="invite_text">邀请好友扫码</view>
				<view class="invite_text">更多好礼等着你</view>
			</view>
		</view>
		<view class="content" v-if="active == 1 | embedded">
			<!-- <view class="sort" v-if="ticketList.length>0">
				排序
				<image class="arrow_down" :src="IMGLink+'/my/arrow-down-outline.png'" mode="widthFix"></image>
			</view> -->
			<scroll-view scroll-y="true" class="scroll-Y" :scroll-y="true" :refresher-enabled="true"
				:refresher-threshold="45" refresher-background="#EFF0F1" @refresherrefresh="onRefresh"
				:refresher-triggered="refresh">
				<view class="fanslist" :class="{'mincative':embedded}">
					<view class="fans_one" v-for="(item,index) in ticketList" :key="index" @click="deepC(item.user_fans_id)">
						<view class="fans_one_left">
							<image class="user_img" :src="item.headimgurl" mode="widthFix"></image>
							<view class="userinfo">
								<view>{{item.nickname}}</view>
								<text class="type">{{item.fans_count}}</text>
							</view>
						</view>
						<view class="fans_one_right">
							<text style="line-height: 48rpx;">{{item.user_level_id}}</text>
							<view class="create_time">
								{{item.create_date}}
							</view>
						</view>
					</view>

					<view v-show="isLoadMore && ticketList.length >0">
						<!-- <uni-load-more :status="loadStatus"></uni-load-more> -->
					</view>

					<view class="nodata" v-if="ticketList.length == 0">
						<image class="empty_img" :src="IMGLink+'/my/empty.png'" mode="widthFix"></image>
						<view>没有你想要的内容</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		version
	} from "@/common/config.js";
	import {
		addresslist
	} from "@/api/my/address.js";
	import {
		createqrcode
	} from '@/api/shopping/shopping';
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				IMGLink: this.IMGLink,
				active: 0,
				typeList: [{
					name: '邀请码'
				}, {
					name: '推广粉丝'
				}],
				ticketList: [],
				page: 1, //页码
				size: '10',
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore: false, //是否加载中
				refresh: false, // 下拉刷新标示
				codeUrl:"",
				embedded:version.embedded
			}
		},
		computed: {
			...mapState(['userinfo'])
		},
		onLoad() {
			if(this.active == 0){
				this.getCode();
			}
			if(this.active == 1 | this.embedded){
				this.getDataList();
			}
		},
		methods: {
			getCode(){
				createqrcode({
					scene: 'invitationcode=' + this.userinfo.invitation_code
				}).then(({
					data: {
						url
					}
				}) => {
					this.codeUrl = url;
				})
			},
			getDataList() {
				uni.showLoading({
					title: '加载中'
				});
				addresslist('getUserFansList', {
					page: this.page,
					page_size: this.size,
					user_id: this.userinfo.id,
				}).then(res => {
					let datas = res.data.list;

					this.ticketList = this.page == 1 ? datas : this.ticketList.concat(datas);
					if (datas.length < this.size) { //小于size数，停止请求
						this.isLoadMore = true;
						this.loadStatus = 'nomore';
					} else {
						this.isLoadMore = false;
					}
					uni.hideLoading();

					this.refresh = false;
				}).catch(error => {
					uni.hideLoading();
					this.isLoadMore = false;
				})
			},
			changeType(item, index) {
				this.active = index;
				if (index == 1) {
					this.page = 1;
					this.getDataList();
				}else{
					this.getCode();
				}
			},
			deepC(userid) {
				uni.navigateTo({
					url: `/pagesA/my/fans/deepfanslist?userid=${userid}`
				})
			},
			onRefresh() {
				this.refresh = true;
				this.page = 1;
				this.getDataList();
			},
			onReachBottom() {
				if (!this.isLoadMore && this.active == 1) { //此处判断，上锁，防止重复请求
					this.isLoadMore = true;
					this.page++;
					this.getDataList();
				}
			},

		}
	}
</script>
<style>
	page {
		background-color: #EFF0F1;
	}
</style>
<style lang="scss" scoped>
	@import "../my.scss";

	// 横向滑动tab
	.scroll-view_H {
		background-color: #FFFFFF;

		.slide_type_list {
			display: flex;
			padding: 20upx 30upx;

			.slide_type_list_view {
				width: 50%;
				padding-bottom: 10rpx;
				font-size: 28rpx;
				color: #0B0B0D;
				margin-right: 30rpx;

				view {
					text-align: center;
				}
			}

			.is_selected {
				color: #070707;
				font-weight: 500;
				position: relative;
			}

			.is_selected:before {
				content: '';
				position: absolute;
				width: 44rpx;
				height: 8rpx;
				left: 50%;
				margin-left: -24rpx;
				bottom: -4rpx;
				background-color: #F54642;
			}
		}
	}

	.content {
		.sort {
			@include flexLayout(center, flext-start);
			line-height: 62rpx;
			color: #717171;
			font-size: 24rpx;
			padding-left: 20rpx;
			padding-top: 16rpx;

			.arrow_down {
				width: 32rpx;
			}
		}

		.fanslist {
			min-height: 90vh;
			
			background-color: #FFFFFF;
			padding: 16rpx 30rpx;
			color: #181818;
			font-size: 24rpx;

			.fans_one {
				@include flexLayout(center, space-between);
				height: 112rpx;
				
				&_left {
					@include flexLayout(center, flex-start);
					color: #181818;
					font-size: 28rpx;
					height: 100%;

					.user_img {
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
						margin-right: 12rpx;
					}

					.type {
						line-height: 48rpx;
						color: #626262;
						font-size: 24rpx;
					}
				}

				&_right {
					font-size: 20rpx;
					text-align: right;
					height: 100%;
					display: flex;
					justify-content: space-between;
					flex-direction: column;
					
					.create_time {
						line-height: 48rpx;
					}
				}
			}

			.fans_one:not(:first-child) {
				margin-top: 30rpx;
			}
		}
		.mincative{
			min-height: 100vh;
		}
	}

	.invitecode {
		box-sizing: border-box;
		height: 95vh;
		background: linear-gradient(90deg, #F9605A 0%, #FB3024 100%);
		padding: 20% 0;

		.mycode {
			background-color: #FFFFFF;
			@include cards;
			@include flexLayout(center, center);
			flex-direction: column;
			width: 80%;
			padding: 60rpx 0 40rpx;
			margin: 0 10%;

			.title {
				@include flexLayout(center, center);
				color: #070707;
				font-size: 36rpx;

				.name {
					margin: 0 20rpx;
				}

				.circle1,
				.circle2 {
					border-radius: 50%;
					background-color: #ffdedf;
				}

				.circle1 {
					width: 12rpx;
					height: 12rpx;
					margin: 0 12rpx;
				}

				.circle2 {
					width: 20rpx;
					height: 20rpx;
				}
			}

			.code_btn {
				width: 274rpx;
				height: 80rpx;
				line-height: 80rpx;
				background: #F54642;
				border-radius: 10rpx;
				font-size: 40rpx;
				color: #FFFFFF;
				margin: 30rpx 0 80rpx;
			}

			.invite_text {
				line-height: 52rpx;
				font-size: 32rpx;
			}

			.invite_img {
				border-radius: 50%;
				margin: 50rpx 0;
				image{
					width: 338rpx;
					height: 338rpx;
				}
			}

			.line_raduis {
				width: 100%;
				@include flexLayout(center, center);
				position: relative;

				.half_right_raduis {
					position: absolute;
					left: 0;
					width: 20rpx;
					height: 40rpx;
					border-radius: 0 20rpx 20rpx 0;
					line-height: 40rpx;
					background-color: #f95c55;
				}

				.half_left_raduis {
					position: absolute;
					right: 0;
					width: 20rpx;
					height: 40rpx;
					border-radius: 20rpx 0 0 20rpx;
					line-height: 40rpx;
					background-color: #fb3428;
				}

				.line_gray {
					width: 88%;
					margin: 0 6rpx;
					border: 4rpx dashed #EFEFEF;
				}
			}
		}
	}

	.nodata {
		text-align: center;
		color: #7D7D7D;
		font-size: 24rpx;
		margin-top: 50%;

		.empty_img {
			width: 468rpx;
		}
	}
</style>
